
<!DOCTYPE HTML>
<html lang="" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>基础知识 · GitBook</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        
        
        
    
    <link rel="stylesheet" href="gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="3. 脚本编写与执行.html" />
    
    
    <link rel="prev" href="kerberos/README.md" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="Type to search" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="./">
            
                <a href="./">
            
                    
                    前言
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="kerberos/README.md">
            
                <span>
            
                    
                    基础篇
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter active" data-level="1.2.1" data-path="2. 基础.html">
            
                <a href="2. 基础.html">
            
                    
                    基础知识
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.2" data-path="3. 脚本编写与执行.html">
            
                <a href="3. 脚本编写与执行.html">
            
                    
                    脚本编写与执行
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.3" data-path="4. Scoket网络编程.html">
            
                <a href="4. Scoket网络编程.html">
            
                    
                    Scoket网络编程
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.4" data-path="5. 端口扫描与服务爆破.html">
            
                <a href="5. 端口扫描与服务爆破.html">
            
                    
                    端口扫描与服务爆破
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.5" data-path="6. 多线程.html">
            
                <a href="6. 多线程.html">
            
                    
                    多线程
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="ntlm-pian/README.md">
            
                <span>
            
                    
                    进阶篇
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.3.1" data-path="7. WMI对象操作.html">
            
                <a href="7. WMI对象操作.html">
            
                    
                    WMI&dot-net对象操作
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.2" data-path="8. Win32API.html">
            
                <a href="8. Win32API.html">
            
                    
                    Win32API
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.3" data-path="9. Dll注入&shellcode注入&exe注入.html">
            
                <a href="9. Dll注入&shellcode注入&exe注入.html">
            
                    
                    注入操作
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.4" data-path="10. 混淆.html">
            
                <a href="10. 混淆.html">
            
                    
                    混淆
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.5" data-path="11. 日志操作.html">
            
                <a href="11. 日志操作.html">
            
                    
                    日志操作
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="ldap-pian/README.md">
            
                <span>
            
                    
                    应用篇
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.1" data-path="12. 实例使用场景.html">
            
                <a href="12. 实例使用场景.html">
            
                    
                    实例使用场景
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.2" data-path="13. Framework.html">
            
                <a href="13. Framework.html">
            
                    
                    Framework
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            Published with GitBook
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="." >基础知识</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h1 id="powershell2-&#x57FA;&#x7840;">powershell(2)-&#x57FA;&#x7840;</h1>
<blockquote>
<p>&#x672C;&#x8282;&#x4E3B;&#x8981;&#x8BB2;&#x4E00;&#x4E0B;&#x5173;&#x4E8E;powershell&#x4E00;&#x4E9B;&#x7B80;&#x5355;&#x7684;&#x57FA;&#x7840;&#x77E5;&#x8BC6;&#xFF0C;&#x63A8;&#x8350;&#x7F51;&#x7AD9;<a href="http://www.pstips.net/" target="_blank">http://www.pstips.net/</a>&#x5B66;&#x4E60;Powershell&#x7684;&#x4E00;&#x4E9B;&#x57FA;&#x7840;&#x77E5;&#x8BC6;</p>
</blockquote>
<p>&#x8FD9;&#x91CC;&#x662F;&#x4E00;&#x4E9B;&#x7B80;&#x5355;&#x7684;&#x57FA;&#x7840;&#xFF0C;&#x5199;&#x7684;&#x53EF;&#x80FD;&#x6709;&#x4E9B;&#x7B80;&#x964B;&#xFF0C;&#x8FD9;&#x91CC;&#x53EF;&#x80FD;&#x9700;&#x8981;&#x4F60;&#x6709;&#x4E00;&#x4E9B;&#x7F16;&#x7A0B;&#x8BED;&#x8A00;&#x7684;&#x57FA;&#x7840;&#x5C31;&#x80FD;&#x770B;&#x61C2;&#x5566;&#xFF0C;&#x8FD9;&#x91CC;&#x5BF9;&#x4E8E;&#x540E;&#x9762;&#x7684;&#x4EE3;&#x7801;&#x5206;&#x6790;&#x662F;&#x975E;&#x5E38;&#x6709;&#x7528;&#x7684;&#xFF0C;&#x6240;&#x4EE5;&#x8FD8;&#x662F;&#x5E0C;&#x671B;&#x5927;&#x5BB6;&#x7B80;&#x5355;&#x7684;&#x6D4F;&#x89C8;&#x4E00;&#x4E0B;&#x57FA;&#x7840;&#x77E5;&#x8BC6;&#x3002;</p>
<h2 id="&#x53D8;&#x91CF;">&#x53D8;&#x91CF;</h2>
<p>&#x53D8;&#x91CF;&#x90FD;&#x662F;&#x4EE5;<code>$</code>&#x5F00;&#x5934;, &#x662F;&#x5F3A;&#x7C7B;&#x578B;&#x8BED;&#x8A00;, &#x8BED;&#x8A00;&#x662F;&#x5927;&#x5C0F;&#x5199;&#x4E0D;&#x654F;&#x611F;&#x7684;</p>
<p>&#x63D0;&#x4E00;&#x63D0;&#x53D8;&#x91CF;&#x4FDD;&#x62A4;&#x4E0E;&#x5E38;&#x91CF;&#x7684;&#x58F0;&#x660E;&#xFF1A;<code>New-Variable num -Value 100 -Force -Option readonly</code>&#x8FD9;&#x6837;&#x5C31;&#x5F97;&#x5230;&#x4E00;&#x4E2A;&#x53D7;&#x4FDD;&#x62A4;&#x7684;&#x53D8;&#x91CF;<code>$num</code>&#xFF0C;&#x5982;&#x679C;&#x8981;&#x9500;&#x6BC1;&#x5B83;&#x53EA;&#x80FD;&#x901A;&#x8FC7;<code>del $num</code>&#x5220;&#x9664;&#x3002;&#x5982;&#x679C;&#x8981;&#x58F0;&#x660E;&#x5E38;&#x91CF;&#x5219;&#x7528;<code>New-Variable num -Value 100 -Force -Option constant</code></p>
<h2 id="&#x6570;&#x7EC4;">&#x6570;&#x7EC4;</h2>
<h3 id="&#x6570;&#x7EC4;&#x7684;&#x521B;&#x5EFA;&#xFF1A;">&#x6570;&#x7EC4;&#x7684;&#x521B;&#x5EFA;&#xFF1A;</h3>
<p>&#x6570;&#x7EC4;&#x7684;&#x521B;&#x5EFA;&#x53EF;&#x4EE5;&#x901A;&#x8FC7;&#x4E0B;&#x9762;&#x4E94;&#x79CD;&#x65B9;&#x5F0F;&#x6765;&#x521B;&#x5EFA;&#xFF0C;&#x5728;&#x9002;&#x5F53;&#x7684;&#x6761;&#x4EF6;&#x4E0B;&#x9009;&#x62E9;&#x9002;&#x5F53;&#x7684;&#x65B9;&#x5F0F;&#x521B;&#x5EFA;&#x5373;&#x53EF;</p>
<pre><code class="lang-powershell"><span class="hljs-variable">$array</span> = <span class="hljs-number">1</span>,<span class="hljs-number">2</span>,<span class="hljs-number">3</span>,<span class="hljs-number">4</span>
<span class="hljs-variable">$array</span> = <span class="hljs-number">1</span>..<span class="hljs-number">4</span>
<span class="hljs-variable">$array</span>=<span class="hljs-number">1</span>,<span class="hljs-string">&quot;2017&quot;</span>,([System.Guid]::NewGuid()),(<span class="hljs-built_in">get-date</span>)
<span class="hljs-variable">$a</span>=@()  <span class="hljs-comment"># &#x7A7A;&#x6570;&#x7EC4;</span>
<span class="hljs-variable">$a</span>=,<span class="hljs-string">&quot;1&quot;</span> <span class="hljs-comment"># &#x4E00;&#x4E2A;&#x5143;&#x7D20;&#x7684;&#x6570;&#x7EC4;</span>
</code></pre>
<h3 id="&#x6570;&#x7EC4;&#x7684;&#x8BBF;&#x95EE;">&#x6570;&#x7EC4;&#x7684;&#x8BBF;&#x95EE;</h3>
<p>&#x6570;&#x7EC4;&#x7684;&#x8BBF;&#x95EE;&#x548C;C&#x7C7B;&#x4F3C;&#xFF0C;&#x7B2C;&#x4E00;&#x4F4D;&#x5143;&#x7D20;&#x5B9E;&#x7528;&#x4E0B;&#x6807;0&#x6765;&#x8BBF;&#x95EE;&#x5373;<code>$array[0]</code>,&#x6211;&#x4EEC;&#x6765;&#x770B;&#x770B;ipconfig&#x83B7;&#x53D6;&#x5230;&#x7684;&#x6570;&#x636E;</p>
<pre><code class="lang-powershell"><span class="hljs-variable">$ip</span> = ipconfig
<span class="hljs-variable">$ip</span>[<span class="hljs-number">1</span>] <span class="hljs-comment"># &#x83B7;&#x53D6;ipconfig&#x7B2C;&#x4E8C;&#x884C;&#x7684;&#x6570;&#x636E;</span>
</code></pre>
<h3 id="&#x6570;&#x7EC4;&#x7684;&#x5224;&#x65AD;">&#x6570;&#x7EC4;&#x7684;&#x5224;&#x65AD;</h3>
<p><code>$test -is [array]</code></p>
<h3 id="&#x6570;&#x7EC4;&#x7684;&#x8FFD;&#x52A0;">&#x6570;&#x7EC4;&#x7684;&#x8FFD;&#x52A0;:</h3>
<p><code>$books += &quot;&#x5143;&#x7D20;4&quot;</code></p>
<h2 id="&#x54C8;&#x5E0C;&#x8868;">&#x54C8;&#x5E0C;&#x8868;</h2>
<h3 id="&#x54C8;&#x5E0C;&#x8868;&#x7684;&#x521B;&#x5EFA;&#xFF1A;">&#x54C8;&#x5E0C;&#x8868;&#x7684;&#x521B;&#x5EFA;&#xFF1A;</h3>
<p><code>$stu=@{ Name = &quot;test&quot;;Age=&quot;12&quot;;sex=&quot;man&quot; }</code></p>
<h3 id="&#x54C8;&#x5E0C;&#x8868;&#x91CC;&#x5B58;&#x6570;&#x7EC4;&#xFF1A;">&#x54C8;&#x5E0C;&#x8868;&#x91CC;&#x5B58;&#x6570;&#x7EC4;&#xFF1A;</h3>
<p><code>$stu=@{ Name = &quot;hei&quot;;Age=&quot;12&quot;;sex=&quot;man&quot;;Books=&quot;kali&quot;,&quot;sqlmap&quot;,&quot;powershell&quot; }</code></p>
<h3 id="&#x54C8;&#x5E0C;&#x8868;&#x7684;&#x63D2;&#x5165;&#x4E0E;&#x5220;&#x9664;">&#x54C8;&#x5E0C;&#x8868;&#x7684;&#x63D2;&#x5165;&#x4E0E;&#x5220;&#x9664;:</h3>
<pre><code class="lang-powershell"><span class="hljs-variable">$Student</span>=@{}
<span class="hljs-variable">$Student</span>.Name=<span class="hljs-string">&quot;hahaha&quot;</span>
<span class="hljs-variable">$stu</span>.Remove(<span class="hljs-string">&quot;Name&quot;</span>)
</code></pre>
<h2 id="&#x5BF9;&#x8C61;">&#x5BF9;&#x8C61;</h2>
<p>&#x5728;powershell&#x4E2D;&#x4E00;&#x5207;&#x90FD;&#x53EF;&#x4EE5;&#x89C6;&#x4E3A;&#x5BF9;&#x8C61;&#xFF0C;&#x5305;&#x7F57;&#x4E07;&#x8C61;&#x3002;</p>
<h3 id="&#x67E5;&#x770B;&#x5BF9;&#x8C61;&#x7ED3;&#x6784;-get-member">&#x67E5;&#x770B;&#x5BF9;&#x8C61;&#x7ED3;&#x6784; (Get-Member)</h3>
<p>&#x7531;&#x4E8E;&#x5BF9;&#x8C61;&#x5728; Windows PowerShell &#x4E2D;&#x626E;&#x6F14;&#x4E86;&#x5982;&#x6B64;&#x91CD;&#x8981;&#x7684;&#x89D2;&#x8272;&#xFF0C;&#x56E0;&#x6B64;&#x5B58;&#x5728;&#x51E0;&#x4E2A;&#x7528;&#x4E8E;&#x5904;&#x7406;&#x4EFB;&#x610F;&#x5BF9;&#x8C61;&#x7C7B;&#x578B;&#x7684;&#x672C;&#x673A;&#x547D;&#x4EE4;&#x3002; &#x6700;&#x91CD;&#x8981;&#x7684;&#x4E00;&#x4E2A;&#x662F; Get-Member &#x547D;&#x4EE4;&#x3002;</p>
<pre><code class="lang-powershell"><span class="hljs-built_in">Get-Process</span> | <span class="hljs-built_in">Get-Member</span> | <span class="hljs-built_in">Out-Host</span> -Paging
TypeName: System.Diagnostics.Process

Name                           MemberType     Definition
----                           ----------     ----------
Handles                        AliasProperty  Handles = Handlecount
Name                           AliasProperty  Name = ProcessName
NPM                            AliasProperty  NPM = NonpagedSystemMemorySize
PM                             AliasProperty  PM = PagedMemorySize
VM                             AliasProperty  VM = VirtualMemorySize
WS                             AliasProperty  WS = WorkingSet
add_Disposed                   Method         System.Void add_Disposed(Event...
...
</code></pre>
<p>&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x901A;&#x8FC7;&#x7B5B;&#x9009;&#x60F3;&#x8981;&#x67E5;&#x770B;&#x7684;&#x5143;&#x7D20;&#xFF0C;&#x8BA9;&#x8FD9;&#x4E2A;&#x5197;&#x957F;&#x7684;&#x4FE1;&#x606F;&#x5217;&#x8868;&#x66F4;&#x6613;&#x4E8E;&#x4F7F;&#x7528;&#x3002; Get-Member &#x547D;&#x4EE4;&#x4EC5;&#x5141;&#x8BB8;&#x4F60;&#x5217;&#x51FA;&#x5C5E;&#x6027;&#x6210;&#x5458;&#x3002; &#x5C5E;&#x6027;&#x7684;&#x5F62;&#x5F0F;&#x6709;&#x6570;&#x79CD;&#x3002; &#x5982;&#x679C;&#x5C06; Get-Member MemberType &#x53C2;&#x6570;&#x8BBE;&#x7F6E;&#x4E3A;&#x503C;&#x5C5E;&#x6027;&#xFF0C;&#x5219; cmdlet &#x5C06;&#x663E;&#x793A;&#x4EFB;&#x4F55;&#x7C7B;&#x578B;&#x7684;&#x5C5E;&#x6027; &#x3002; &#x751F;&#x6210;&#x7684;&#x5217;&#x8868;&#x4ECD;&#x4F1A;&#x5F88;&#x957F;&#xFF0C;&#x4F46;&#x8F83;&#x4E4B;&#x524D;&#x66F4;&#x6613;&#x4E8E;&#x7BA1;&#x7406;&#xFF1A;</p>
<pre><code class="lang-powershell">PS&gt; <span class="hljs-built_in">Get-Process</span> | <span class="hljs-built_in">Get-Member</span> -MemberType Properties

   TypeName: System.Diagnostics.Process

Name                       MemberType     Definition
----                       ----------     ----------
Handles                    AliasProperty  Handles = Handlecount
Name                       AliasProperty  Name = ProcessName
...
ExitCode                   <span class="hljs-built_in">Property</span>       System.Int32 ExitCode {get;}
...
Handle                     <span class="hljs-built_in">Property</span>       System.IntPtr Handle {get;}
...
CPU                        ScriptProperty System.Object CPU {get=<span class="hljs-variable">$this</span>.Total...
...
Path                       ScriptProperty System.Object Path {get=<span class="hljs-variable">$this</span>.Main...
...
</code></pre>
<h3 id="&#x9009;&#x62E9;&#x5BF9;&#x8C61;&#x90E8;&#x4EF6;-select-object">&#x9009;&#x62E9;&#x5BF9;&#x8C61;&#x90E8;&#x4EF6; (Select-Object)</h3>
<p>&#x53EF;&#x4EE5;&#x4F7F;&#x7528; Select-Object cmdlet &#x521B;&#x5EFA;&#x65B0;&#x7684;&#x81EA;&#x5B9A;&#x4E49; PowerShell &#x5BF9;&#x8C61;&#xFF08;&#x5305;&#x542B;&#x4ECE;&#x7528;&#x4E8E;&#x521B;&#x5EFA;&#x5B83;&#x4EEC;&#x7684;&#x5BF9;&#x8C61;&#x4E2D;&#x9009;&#x62E9;&#x7684;&#x5C5E;&#x6027;&#xFF09;&#x3002; &#x952E;&#x5165;&#x4E0B;&#x9762;&#x7684;&#x547D;&#x4EE4;&#x4EE5;&#x521B;&#x5EFA;&#x4EC5;&#x5305;&#x62EC; Win32_LogicalDisk WMI &#x7C7B;&#x7684; Name &#x548C; FreeSpace &#x5C5E;&#x6027;&#x7684;&#x65B0;&#x5BF9;&#x8C61;&#xFF1A;</p>
<pre><code class="lang-powershell">Get-CimInstance -Class Win32_LogicalDisk | <span class="hljs-built_in">Select-Object</span> -Property Name,FreeSpace
Name      FreeSpace
----      ---------
C:      <span class="hljs-number">50664845312</span>
</code></pre>
<p>&#x53EF;&#x4EE5;&#x4F7F;&#x7528; Select-Object &#x521B;&#x5EFA;&#x8BA1;&#x7B97;&#x5C5E;&#x6027;&#x3002; &#x8FD9;&#x6837;&#x5373;&#x53EF;&#x4EE5;&#x4EE5;&#x5341;&#x4EBF;&#x5B57;&#x8282;&#x4E3A;&#x5355;&#x4F4D;&#x663E;&#x793A; FreeSpace&#xFF0C;&#x800C;&#x975E;&#x4EE5;&#x5B57;&#x8282;&#x4E3A;&#x5355;&#x4F4D;&#x3002;</p>
<pre><code class="lang-PowerShell">Get-CimInstance -Class Win32_LogicalDisk |
  <span class="hljs-built_in">Select-Object</span> -Property Name, @{
    label=<span class="hljs-string">&apos;FreeSpace&apos;</span>
    expression={(<span class="hljs-variable">$_</span>.FreeSpace/<span class="hljs-number">1</span>GB).ToString(<span class="hljs-string">&apos;F2&apos;</span>)}
  }

Name    FreeSpace
----    ---------
C:      <span class="hljs-number">47.18</span>
</code></pre>
<h3 id="&#x4ECE;&#x7BA1;&#x9053;&#x4E2D;&#x5220;&#x9664;&#x5BF9;&#x8C61;-where-object">&#x4ECE;&#x7BA1;&#x9053;&#x4E2D;&#x5220;&#x9664;&#x5BF9;&#x8C61; (Where-Object)</h3>
<p>&#x5728; PowerShell &#x4E2D;&#xFF0C;&#x4F60;&#x901A;&#x5E38;&#x4F1A;&#x751F;&#x6210;&#x548C;&#x4F20;&#x9012;&#x6BD4;&#x9884;&#x671F;&#x66F4;&#x591A;&#x7684;&#x5BF9;&#x8C61;&#x5230;&#x7BA1;&#x9053;&#x4E2D;&#x3002; &#x53EF;&#x4EE5;&#x901A;&#x8FC7;&#x4F7F;&#x7528; Format-* cmdlet &#x6307;&#x5B9A;&#x7279;&#x5B9A;&#x5BF9;&#x8C61;&#x7684;&#x5C5E;&#x6027;&#x8FDB;&#x884C;&#x663E;&#x793A;&#xFF0C;&#x4F46;&#x662F;&#x8FD9;&#x5BF9;&#x4ECE;&#x663E;&#x793A;&#x4E2D;&#x5220;&#x9664;&#x6574;&#x4E2A;&#x5BF9;&#x8C61;&#x7684;&#x95EE;&#x9898;&#x6CA1;&#x6709;&#x4EFB;&#x4F55;&#x5E2E;&#x52A9;&#x3002; &#x4F60;&#x53EF;&#x80FD;&#x5E0C;&#x671B;&#x5728;&#x7BA1;&#x9053;&#x672B;&#x5C3E;&#x4E4B;&#x524D;&#x7B5B;&#x9009;&#x5BF9;&#x8C61;&#xFF0C;&#x4EE5;&#x4FBF;&#x4F60;&#x53EF;&#x4EE5;&#x53EA;&#x5BF9;&#x521D;&#x59CB;&#x751F;&#x6210;&#x5BF9;&#x8C61;&#x7684;&#x5B50;&#x96C6;&#x6267;&#x884C;&#x64CD;&#x4F5C;&#x3002;</p>
<h4 id="&#x4F7F;&#x7528;-where-object-&#x6267;&#x884C;&#x7B80;&#x5355;&#x6D4B;&#x8BD5;">&#x4F7F;&#x7528; Where-Object &#x6267;&#x884C;&#x7B80;&#x5355;&#x6D4B;&#x8BD5;</h4>
<p>&#x501F;&#x52A9; PowerShell &#x4E2D;&#x7684; Where-Object cmdlet&#xFF0C;&#x53EF;&#x4EE5;&#x6D4B;&#x8BD5;&#x7BA1;&#x9053;&#x4E2D;&#x7684;&#x6BCF;&#x4E2A;&#x5BF9;&#x8C61;&#xFF0C;&#x5E76;&#x6CBF;&#x7BA1;&#x9053;&#x4EC5;&#x4F20;&#x9012;&#x6EE1;&#x8DB3;&#x7279;&#x5B9A;&#x6D4B;&#x8BD5;&#x6761;&#x4EF6;&#x7684;&#x5BF9;&#x8C61;&#x3002; &#x5C06;&#x4ECE;&#x7BA1;&#x9053;&#x4E2D;&#x5220;&#x9664;&#x672A;&#x901A;&#x8FC7;&#x6D4B;&#x8BD5;&#x7684;&#x5BF9;&#x8C61;&#x3002; &#x6D4B;&#x8BD5;&#x6761;&#x4EF6;&#x4EE5; FilterScript &#x53C2;&#x6570;&#x503C;&#x7684;&#x5F62;&#x5F0F;&#x63D0;&#x4F9B;&#x3002;
&#x6BD4;&#x8F83;&#x8FD0;&#x7B97;&#x7B26;    &#x542B;&#x4E49;    &#x793A;&#x4F8B;&#xFF08;&#x8FD4;&#x56DE; True&#xFF09;
&#x51FA;&#x4E8E;&#x5206;&#x6790;&#x8003;&#x8651;&#xFF0C;&lt;&#x3001;&gt; &#x548C; = &#x7B49;&#x7B26;&#x53F7;&#x4E0D;&#x7528;&#x4F5C;&#x6BD4;&#x8F83;&#x8FD0;&#x7B97;&#x7B26;&#x3002; &#x76F8;&#x53CD;&#xFF0C;&#x6BD4;&#x8F83;&#x8FD0;&#x7B97;&#x7B26;&#x7531;&#x5B57;&#x6BCD;&#x7EC4;&#x6210;&#x3002;&#x6BD4;&#x5982;-eq&#x3001;-ne&#x3001;-like&#x7B49;&#x7B49;&#x3002;
Where-Object &#x811A;&#x672C;&#x5757;&#x4F7F;&#x7528;&#x7279;&#x6B8A;&#x53D8;&#x91CF; $_ &#x6765;&#x6307;&#x4EE3;&#x7BA1;&#x9053;&#x4E2D;&#x7684;&#x5F53;&#x524D;&#x5BF9;&#x8C61;&#x3002; &#x4EE5;&#x4E0B;&#x662F;&#x5176;&#x5DE5;&#x4F5C;&#x539F;&#x7406;&#x793A;&#x4F8B;&#x3002; &#x5982;&#x679C;&#x4F60;&#x6709;&#x4E00;&#x4E2A;&#x6570;&#x5B57;&#x5217;&#x8868;&#xFF0C;&#x4E14;&#x5E0C;&#x671B;&#x4EC5;&#x8FD4;&#x56DE;&#x5C0F;&#x4E8E; 3 &#x7684;&#x6570;&#x5B57;&#xFF0C;&#x5219;&#x53EF;&#x4F7F;&#x7528; Where-Object &#x901A;&#x8FC7;&#x952E;&#x5165;&#x4EE5;&#x4E0B;&#x5185;&#x5BB9;&#x6765;&#x7B5B;&#x9009;&#x6570;&#x5B57;&#xFF1A;</p>
<pre><code class="lang-powershell"><span class="hljs-number">1</span>,<span class="hljs-number">2</span>,<span class="hljs-number">3</span>,<span class="hljs-number">4</span> | <span class="hljs-built_in">Where-Object</span> {<span class="hljs-variable">$_</span> <span class="hljs-nomarkup">-lt</span> <span class="hljs-number">3</span>}
<span class="hljs-number">1</span>
<span class="hljs-number">2</span>
</code></pre>
<h4 id="&#x57FA;&#x4E8E;&#x5BF9;&#x8C61;&#x5C5E;&#x6027;&#x8FDB;&#x884C;&#x7B5B;&#x9009;">&#x57FA;&#x4E8E;&#x5BF9;&#x8C61;&#x5C5E;&#x6027;&#x8FDB;&#x884C;&#x7B5B;&#x9009;</h4>
<p>&#x7531;&#x4E8E; $_ &#x6307;&#x4EE3;&#x5F53;&#x524D;&#x7BA1;&#x9053;&#x5BF9;&#x8C61;&#xFF0C;&#x56E0;&#x6B64;&#x53EF;&#x4EE5;&#x8BBF;&#x95EE;&#x5B83;&#x7684;&#x5C5E;&#x6027;&#x8FDB;&#x884C;&#x6D4B;&#x8BD5;&#x3002;
&#x4F8B;&#x5982;&#xFF0C;&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x770B;&#x770B; WMI &#x4E2D;&#x7684; Win32_SystemDriver &#x7C7B;&#x3002; &#x4E00;&#x4E2A;&#x7279;&#x5B9A;&#x7684;&#x7CFB;&#x7EDF;&#x4E0A;&#x53EF;&#x80FD;&#x6709;&#x6570;&#x767E;&#x4E2A;&#x7CFB;&#x7EDF;&#x9A71;&#x52A8;&#x7A0B;&#x5E8F;&#xFF0C;&#x4F46;&#x662F;&#x4F60;&#x53EF;&#x80FD;&#x53EA;&#x5BF9;&#x7279;&#x5B9A;&#x4E00;&#x4E9B;&#x7CFB;&#x7EDF;&#x9A71;&#x52A8;&#x7A0B;&#x5E8F;&#x611F;&#x5174;&#x8DA3;&#xFF0C;&#x4F8B;&#x5982;&#x90A3;&#x4E9B;&#x5F53;&#x524D;&#x6B63;&#x5728;&#x8FD0;&#x884C;&#x7684;&#x7A0B;&#x5E8F;&#x3002; &#x5BF9;&#x4E8E; Win32_SystemDriver &#x7C7B;&#xFF0C;&#x76F8;&#x5173;&#x5C5E;&#x6027;&#x662F; State &#x3002; &#x4F60;&#x53EF;&#x4EE5;&#x7B5B;&#x9009;&#x7CFB;&#x7EDF;&#x9A71;&#x52A8;&#x7A0B;&#x5E8F;&#xFF0C;&#x901A;&#x8FC7;&#x952E;&#x5165;&#x4EE5;&#x4E0B;&#x5185;&#x5BB9;&#x4EC5;&#x9009;&#x62E9;&#x6B63;&#x5728;&#x8FD0;&#x884C;&#x7684;&#x9A71;&#x52A8;&#x7A0B;&#x5E8F;&#xFF1A;</p>
<pre><code class="lang-powershell">Get-CimInstance -Class Win32_SystemDriver |
  <span class="hljs-built_in">Where-Object</span> {<span class="hljs-variable">$_</span>.State <span class="hljs-nomarkup">-eq</span> <span class="hljs-string">&apos;Running&apos;</span>}
</code></pre>
<p>&#x8FD9;&#x4ECD;&#x4F1A;&#x751F;&#x6210;&#x4E00;&#x4E2A;&#x8F83;&#x957F;&#x7684;&#x5217;&#x8868;&#x3002; &#x4F60;&#x53EF;&#x80FD;&#x8FD8;&#x5E0C;&#x671B;&#x8FDB;&#x884C;&#x7B5B;&#x9009;&#xFF0C;&#x4EE5;&#x901A;&#x8FC7;&#x6D4B;&#x8BD5; StartMode &#x503C;&#x4EC5;&#x9009;&#x62E9;&#x81EA;&#x52A8;&#x542F;&#x52A8;&#x7684;&#x9A71;&#x52A8;&#x7A0B;&#x5E8F;&#x96C6;&#xFF1A;</p>
<pre><code class="lang-powershell">DisplayName : RAS Asynchronous Media Driver
Name        : AsyncMac
State       : Running
Status      : OK
Started     : True

DisplayName : Audio Stub Driver
Name        : audstub
State       : Running
Status      : OK
Started     : True
...
</code></pre>
<p>&#x8FD9;&#x4E3A;&#x6211;&#x4EEC;&#x63D0;&#x4F9B;&#x4E86;&#x5927;&#x91CF;&#x4E0D;&#x518D;&#x9700;&#x8981;&#x7684;&#x4FE1;&#x606F;&#xFF0C;&#x56E0;&#x4E3A;&#x6211;&#x4EEC;&#x77E5;&#x9053;&#x9A71;&#x52A8;&#x7A0B;&#x5E8F;&#x6B63;&#x5728;&#x8FD0;&#x884C;&#x3002; &#x4E8B;&#x5B9E;&#x4E0A;&#xFF0C;&#x6B64;&#x65F6;&#x6211;&#x4EEC;&#x53EF;&#x80FD;&#x9700;&#x8981;&#x7684;&#x552F;&#x4E00;&#x4FE1;&#x606F;&#x5C31;&#x662F;&#x540D;&#x79F0;&#x548C;&#x663E;&#x793A;&#x540D;&#x3002; &#x4E0B;&#x9762;&#x7684;&#x547D;&#x4EE4;&#x4EC5;&#x5305;&#x62EC;&#x8FD9;&#x4E24;&#x79CD;&#x5C5E;&#x6027;&#xFF0C;&#x4ECE;&#x800C;&#x4F7F;&#x8F93;&#x51FA;&#x66F4;&#x7B80;&#x5355;&#xFF1A;</p>
<pre><code class="lang-powershell">Get-CimInstance -Class Win32_SystemDriver |
  <span class="hljs-built_in">Where-Object</span> {<span class="hljs-variable">$_</span>.State <span class="hljs-nomarkup">-eq</span> <span class="hljs-string">&quot;Running&quot;</span>} |
    <span class="hljs-built_in">Where-Object</span> {<span class="hljs-variable">$_</span>.StartMode <span class="hljs-nomarkup">-eq</span> <span class="hljs-string">&quot;Manual&quot;</span>} |
      <span class="hljs-built_in">Format-Table</span> -Property Name,DisplayName

Name              DisplayName
----              -----------
AsyncMac               RAS Asynchronous Media Driver
bindflt                Windows Bind <span class="hljs-keyword">Filter</span> Driver
bowser                 Browser
CompositeBus           Composite Bus Enumerator Driver
condrv                 Console Driver
HdAudAddService        Microsoft <span class="hljs-number">1.1</span> UAA <span class="hljs-keyword">Function</span> Driver <span class="hljs-keyword">for</span> High Definition Audio Service
HDAudBus               Microsoft UAA Bus Driver <span class="hljs-keyword">for</span> High Definition Audio
HidUsb                 Microsoft HID Class Driver
HTTP                   HTTP Service
igfx                   igfx
IntcDAud               Intel(R) Display Audio
intelppm               Intel Processor Driver
...
</code></pre>
<h3 id="&#x521B;&#x5EFA;-net-&#x5BF9;&#x8C61;">&#x521B;&#x5EFA; .NET &#x5BF9;&#x8C61;</h3>
<p>&#x5B58;&#x5728;&#x5177;&#x6709; .NET Framework &#x548C; COM &#x63A5;&#x53E3;&#x7684;&#x8F6F;&#x4EF6;&#x7EC4;&#x4EF6;&#xFF0C;&#x4F7F;&#x7528;&#x5B83;&#x4EEC;&#x53EF;&#x6267;&#x884C;&#x8BB8;&#x591A;&#x7CFB;&#x7EDF;&#x7BA1;&#x7406;&#x4EFB;&#x52A1;&#x3002; Windows PowerShell &#x5141;&#x8BB8;&#x4F60;&#x4F7F;&#x7528;&#x8FD9;&#x4E9B;&#x7EC4;&#x4EF6;&#xFF0C;&#x56E0;&#x6B64;&#x4F60;&#x5C06;&#x4E0D;&#x9650;&#x4E8E;&#x6267;&#x884C;&#x53EF;&#x901A;&#x8FC7;&#x4F7F;&#x7528; cmdlet &#x6267;&#x884C;&#x7684;&#x4EFB;&#x52A1;&#x3002; Windows PowerShell &#x521D;&#x59CB;&#x7248;&#x672C;&#x4E2D;&#x7684;&#x8BB8;&#x591A; cmdlet &#x5BF9;&#x8FDC;&#x7A0B;&#x8BA1;&#x7B97;&#x673A;&#x65E0;&#x6548;&#x3002; &#x6211;&#x4EEC;&#x5C06;&#x6F14;&#x793A;&#x5982;&#x4F55;&#x901A;&#x8FC7;&#x76F4;&#x63A5;&#x4ECE; Windows PowerShell &#x4F7F;&#x7528; .NET Framework System.Diagnostics.EventLog &#x7C7B;&#x5728;&#x7BA1;&#x7406;&#x4E8B;&#x4EF6;&#x65E5;&#x5FD7;&#x65F6;&#x7ED5;&#x8FC7;&#x6B64;&#x9650;&#x5236;&#x3002;</p>
<h4 id="&#x4F7F;&#x7528;-new-object-&#x8FDB;&#x884C;&#x4E8B;&#x4EF6;&#x65E5;&#x5FD7;&#x8BBF;&#x95EE;">&#x4F7F;&#x7528; New-Object &#x8FDB;&#x884C;&#x4E8B;&#x4EF6;&#x65E5;&#x5FD7;&#x8BBF;&#x95EE;</h4>
<p>.NET Framework &#x7C7B;&#x5E93;&#x5305;&#x62EC;&#x4E00;&#x4E2A;&#x540D;&#x4E3A; System.Diagnostics.EventLog &#x7684;&#x7C7B;&#xFF0C;&#x8BE5;&#x7C7B;&#x53EF;&#x7528;&#x4E8E;&#x7BA1;&#x7406;&#x4E8B;&#x4EF6;&#x65E5;&#x5FD7;&#x3002; &#x53EF;&#x4EE5;&#x901A;&#x8FC7;&#x4F7F;&#x7528;&#x5177;&#x6709; TypeName &#x53C2;&#x6570;&#x7684; New-Object cmdlet &#x521B;&#x5EFA; .NET Framework &#x7C7B;&#x7684;&#x65B0;&#x5B9E;&#x4F8B;&#x3002; &#x4F8B;&#x5982;&#xFF0C;&#x4EE5;&#x4E0B;&#x547D;&#x4EE4;&#x5C06;&#x521B;&#x5EFA;&#x4E8B;&#x4EF6;&#x65E5;&#x5FD7;&#x5F15;&#x7528;&#xFF1A;</p>
<pre><code class="lang-powershell">PS&gt; <span class="hljs-built_in">New-Object</span> -TypeName System.Diagnostics.EventLog

  Max(K) Retain OverflowAction        Entries Name
  ------ ------ --------------        ------- ----
</code></pre>
<p>&#x5C3D;&#x7BA1;&#x8BE5;&#x547D;&#x4EE4;&#x521B;&#x5EFA;&#x4E86; EventLog &#x7C7B;&#x7684;&#x5B9E;&#x4F8B;&#xFF0C;&#x4F46;&#x8BE5;&#x5B9E;&#x4F8B;&#x4E0D;&#x5305;&#x542B;&#x4EFB;&#x4F55;&#x6570;&#x636E;&#x3002; &#x8FD9;&#x662F;&#x56E0;&#x4E3A;&#x6211;&#x4EEC;&#x672A;&#x6307;&#x5B9A;&#x7279;&#x5B9A;&#x7684;&#x4E8B;&#x4EF6;&#x65E5;&#x5FD7;&#x3002; &#x5982;&#x4F55;&#x83B7;&#x53D6;&#x771F;&#x6B63;&#x7684;&#x4E8B;&#x4EF6;&#x65E5;&#x5FD7;&#xFF1F;</p>
<h5 id="&#x5C06;&#x6784;&#x9020;&#x51FD;&#x6570;&#x4E0E;-new-object-&#x4E00;&#x8D77;&#x4F7F;&#x7528;">&#x5C06;&#x6784;&#x9020;&#x51FD;&#x6570;&#x4E0E; New-Object &#x4E00;&#x8D77;&#x4F7F;&#x7528;</h5>
<p>&#x82E5;&#x8981;&#x5F15;&#x7528;&#x7279;&#x5B9A;&#x7684;&#x4E8B;&#x4EF6;&#x65E5;&#x5FD7;&#xFF0C;&#x9700;&#x8981;&#x6307;&#x5B9A;&#x65E5;&#x5FD7;&#x7684;&#x540D;&#x79F0;&#x3002; New-Object &#x5177;&#x6709; ArgumentList &#x53C2;&#x6570;&#x3002; &#x4F5C;&#x4E3A;&#x503C;&#x4F20;&#x9012;&#x5230;&#x6B64;&#x5F62;&#x53C2;&#x7684;&#x5B9E;&#x53C2;&#x5C06;&#x7531;&#x5BF9;&#x8C61;&#x7684;&#x7279;&#x6B8A;&#x7684;&#x542F;&#x52A8;&#x65B9;&#x6CD5;&#x4F7F;&#x7528;&#x3002; &#x6B64;&#x65B9;&#x6CD5;&#x53EB;&#x505A;&#x6784;&#x9020;&#x51FD;&#x6570;&#xFF0C;&#x56E0;&#x4E3A;&#x5B83;&#x5C06;&#x7528;&#x4E8E;&#x6784;&#x9020;&#x5BF9;&#x8C61;&#x3002; &#x4F8B;&#x5982;&#xFF0C;&#x82E5;&#x8981;&#x5BF9;&#x83B7;&#x53D6;&#x5E94;&#x7528;&#x7A0B;&#x5E8F;&#x65E5;&#x5FD7;&#x7684;&#x5F15;&#x7528;&#xFF0C;&#x8BF7;&#x6307;&#x5B9A;&#x5B57;&#x7B26;&#x4E32;&#x201C;Application&#x201D;&#x4F5C;&#x4E3A;&#x5B9E;&#x53C2;</p>
<pre><code class="lang-powershell">PS&gt; <span class="hljs-built_in">New-Object</span> -TypeName System.Diagnostics.EventLog -ArgumentList Application

Max(K) Retain OverflowAction        Entries Name
------ ------ --------------        ------- ----
<span class="hljs-number">16</span>,<span class="hljs-number">384</span>      <span class="hljs-number">7</span> OverwriteOlder          <span class="hljs-number">2</span>,<span class="hljs-number">160</span> Application
</code></pre>
<h5 id="&#x5728;&#x53D8;&#x91CF;&#x4E2D;&#x5B58;&#x50A8;&#x5BF9;&#x8C61;">&#x5728;&#x53D8;&#x91CF;&#x4E2D;&#x5B58;&#x50A8;&#x5BF9;&#x8C61;</h5>
<p>&#x4F60;&#x53EF;&#x80FD;&#x9700;&#x8981;&#x5B58;&#x50A8;&#x5BF9;&#x5BF9;&#x8C61;&#x7684;&#x5F15;&#x7528;&#xFF0C;&#x4EE5;&#x4FBF;&#x5728;&#x5F53;&#x524D;&#x7684; Shell &#x4E2D;&#x4F7F;&#x7528;&#x3002; &#x5C3D;&#x7BA1; Windows PowerShell &#x5141;&#x8BB8;&#x4F7F;&#x7528;&#x7BA1;&#x9053;&#x6267;&#x884C;&#x5927;&#x91CF;&#x64CD;&#x4F5C;&#xFF0C;&#x51CF;&#x5C11;&#x4E86;&#x5BF9;&#x53D8;&#x91CF;&#x7684;&#x9700;&#x6C42;&#xFF0C;&#x4F46;&#x6709;&#x65F6;&#x5728;&#x53D8;&#x91CF;&#x4E2D;&#x5B58;&#x50A8;&#x5BF9;&#x5BF9;&#x8C61;&#x7684;&#x5F15;&#x7528;&#x53EF;&#x4EE5;&#x66F4;&#x65B9;&#x4FBF;&#x5730;&#x64CD;&#x7EB5;&#x8FD9;&#x4E9B;&#x5BF9;&#x8C61;&#x3002;
Windows PowerShell &#x5141;&#x8BB8;&#x4F60;&#x521B;&#x5EFA;&#x5B9E;&#x8D28;&#x4E0A;&#x662F;&#x547D;&#x540D;&#x5BF9;&#x8C61;&#x7684;&#x53D8;&#x91CF;&#x3002; &#x6765;&#x81EA;&#x4EFB;&#x4F55;&#x6709;&#x6548; Windows PowerShell &#x547D;&#x4EE4;&#x7684;&#x8F93;&#x51FA;&#x90FD;&#x53EF;&#x4EE5;&#x5B58;&#x50A8;&#x5728;&#x53D8;&#x91CF;&#x4E2D;&#x3002; &#x53D8;&#x91CF;&#x540D;&#x59CB;&#x7EC8;&#x4EE5; $ &#x5F00;&#x5934;&#x3002; &#x5982;&#x679C;&#x60F3;&#x8981;&#x5C06;&#x5E94;&#x7528;&#x7A0B;&#x5E8F;&#x65E5;&#x5FD7;&#x5F15;&#x7528;&#x5B58;&#x50A8;&#x5728;&#x540D;&#x4E3A; $AppLog &#x7684;&#x53D8;&#x91CF;&#x4E2D;&#xFF0C;&#x8BF7;&#x952E;&#x5165;&#x8BE5;&#x53D8;&#x91CF;&#x7684;&#x540D;&#x79F0;&#xFF0C;&#x540E;&#x8DDF;&#x4E00;&#x4E2A;&#x7B49;&#x53F7;&#xFF0C;&#x7136;&#x540E;&#x952E;&#x5165;&#x7528;&#x4E8E;&#x521B;&#x5EFA;&#x5E94;&#x7528;&#x7A0B;&#x5E8F;&#x65E5;&#x5FD7;&#x5BF9;&#x8C61;&#x7684;&#x547D;&#x4EE4;&#xFF1A;</p>
<pre><code class="lang-powershell">PS&gt; <span class="hljs-variable">$AppLog</span> = <span class="hljs-built_in">New-Object</span> -TypeName System.Diagnostics.EventLog -ArgumentList Application

PS&gt; <span class="hljs-variable">$AppLog</span>

  Max(K) Retain OverflowAction        Entries Name
  ------ ------ --------------        ------- ----
  <span class="hljs-number">16</span>,<span class="hljs-number">384</span>      <span class="hljs-number">7</span> OverwriteOlder          <span class="hljs-number">2</span>,<span class="hljs-number">160</span> Application
</code></pre>
<h5 id="&#x4F7F;&#x7528;-new-object-&#x8BBF;&#x95EE;&#x8FDC;&#x7A0B;&#x4E8B;&#x4EF6;&#x65E5;&#x5FD7;">&#x4F7F;&#x7528; New-Object &#x8BBF;&#x95EE;&#x8FDC;&#x7A0B;&#x4E8B;&#x4EF6;&#x65E5;&#x5FD7;</h5>
<p>&#x4E0A;&#x4E00;&#x8282;&#x4E2D;&#x4F7F;&#x7528;&#x7684;&#x547D;&#x4EE4;&#x4EE5;&#x672C;&#x5730;&#x8BA1;&#x7B97;&#x673A;&#x4E3A;&#x76EE;&#x6807;&#xFF1B;Get-EventLog cmdlet &#x53EF;&#x505A;&#x5230;&#x8FD9;&#x4E00;&#x70B9;&#x3002; &#x82E5;&#x8981;&#x8BBF;&#x95EE;&#x8FDC;&#x7A0B;&#x8BA1;&#x7B97;&#x673A;&#x4E0A;&#x7684;&#x5E94;&#x7528;&#x7A0B;&#x5E8F;&#x65E5;&#x5FD7;&#xFF0C;&#x5FC5;&#x987B;&#x540C;&#x65F6;&#x5C06;&#x65E5;&#x5FD7;&#x540D;&#x79F0;&#x548C;&#x8BA1;&#x7B97;&#x673A;&#x540D;&#x79F0;&#xFF08;&#x6216; IP &#x5730;&#x5740;&#xFF09;&#x4F5C;&#x4E3A;&#x53C2;&#x6570;&#x63D0;&#x4F9B;&#x3002;</p>
<pre><code class="lang-powershell">PS&gt; <span class="hljs-variable">$RemoteAppLog</span> = <span class="hljs-built_in">New-Object</span> -TypeName System.Diagnostics.EventLog Application,<span class="hljs-number">192.168</span>.<span class="hljs-number">1.81</span>
PS&gt; <span class="hljs-variable">$RemoteAppLog</span>

  Max(K) Retain OverflowAction        Entries Name
  ------ ------ --------------        ------- ----
     <span class="hljs-number">512</span>      <span class="hljs-number">7</span> OverwriteOlder            <span class="hljs-number">262</span> Application
</code></pre>
<h5 id="&#x4F7F;&#x7528;&#x5BF9;&#x8C61;&#x65B9;&#x6CD5;&#x6E05;&#x9664;&#x4E8B;&#x4EF6;&#x65E5;&#x5FD7;">&#x4F7F;&#x7528;&#x5BF9;&#x8C61;&#x65B9;&#x6CD5;&#x6E05;&#x9664;&#x4E8B;&#x4EF6;&#x65E5;&#x5FD7;</h5>
<p>&#x5BF9;&#x8C61;&#x901A;&#x5E38;&#x5177;&#x6709;&#x53EF;&#x8C03;&#x7528;&#x4EE5;&#x6267;&#x884C;&#x4EFB;&#x52A1;&#x7684;&#x65B9;&#x6CD5;&#x3002; &#x53EF;&#x4EE5;&#x4F7F;&#x7528; Get-Member &#x6765;&#x663E;&#x793A;&#x4E0E;&#x5BF9;&#x8C61;&#x5173;&#x8054;&#x7684;&#x65B9;&#x6CD5;&#x3002; &#x4E0B;&#x9762;&#x7684;&#x547D;&#x4EE4;&#x548C;&#x5DF2;&#x9009;&#x7684;&#x8F93;&#x51FA;&#x5C06;&#x663E;&#x793A; EventLog &#x7C7B;&#x7684;&#x4E00;&#x4E9B;&#x65B9;&#x6CD5;&#xFF1A;</p>
<pre><code class="lang-powershell">PS&gt; <span class="hljs-variable">$RemoteAppLog</span> | <span class="hljs-built_in">Get-Member</span> -MemberType Method

   TypeName: System.Diagnostics.EventLog

Name                      MemberType Definition
----                      ---------- ----------
...
Clear                     Method     System.Void Clear()
Close                     Method     System.Void Close()
...
GetType                   Method     System.Type GetType()
...
ModifyOverflowPolicy      Method     System.Void ModifyOverflowPolicy(Overfl...
RegisterDisplayName       Method     System.Void RegisterDisplayName(String ...
...
ToString                  Method     System.String ToString()
WriteEntry                Method     System.Void WriteEntry(String message),...
WriteEvent                Method     System.Void WriteEvent(EventInstance in...
</code></pre>
<p>Clear() &#x65B9;&#x6CD5;&#x53EF;&#x4EE5;&#x7528;&#x4E8E;&#x6E05;&#x9664;&#x4E8B;&#x4EF6;&#x65E5;&#x5FD7;&#x3002; &#x8C03;&#x7528;&#x65B9;&#x6CD5;&#x65F6;&#xFF0C;&#x5373;&#x4F7F;&#x8BE5;&#x65B9;&#x6CD5;&#x4E0D;&#x9700;&#x8981;&#x53C2;&#x6570;&#xFF0C;&#x4E5F;&#x5FC5;&#x987B;&#x59CB;&#x7EC8;&#x5728;&#x65B9;&#x6CD5;&#x540D;&#x79F0;&#x540E;&#x7D27;&#x8DDF;&#x62EC;&#x53F7;&#x3002; &#x8FD9;&#x4F7F;&#x5F97; Windows PowerShell &#x65B9;&#x6CD5;&#x80FD;&#x591F;&#x533A;&#x5206;&#x8BE5;&#x65B9;&#x6CD5;&#x548C;&#x5177;&#x6709;&#x76F8;&#x540C;&#x540D;&#x79F0;&#x7684;&#x6F5C;&#x5728;&#x5C5E;&#x6027;&#x3002; &#x952E;&#x5165;&#x4EE5;&#x4E0B;&#x547D;&#x4EE4;&#x4EE5;&#x8C03;&#x7528; Clear &#x65B9;&#x6CD5;&#xFF1A;</p>
<pre><code class="lang-powershell">PS&gt; <span class="hljs-variable">$RemoteAppLog</span>.Clear()
</code></pre>
<h3 id="&#x4F7F;&#x7528;-new-object-&#x521B;&#x5EFA;-com-&#x5BF9;&#x8C61;">&#x4F7F;&#x7528; New-Object &#x521B;&#x5EFA; COM &#x5BF9;&#x8C61;</h3>
<p>&#x53EF;&#x4EE5;&#x4F7F;&#x7528; New-Object &#x6765;&#x5904;&#x7406;&#x7EC4;&#x4EF6;&#x5BF9;&#x8C61;&#x6A21;&#x578B; (COM) &#x7EC4;&#x4EF6;&#x3002; &#x7EC4;&#x4EF6;&#x7684;&#x8303;&#x56F4;&#x4ECE; Windows &#x811A;&#x672C;&#x5BBF;&#x4E3B; (WSH) &#x5305;&#x542B;&#x7684;&#x5404;&#x79CD;&#x5E93;&#x5230; ActiveX &#x5E94;&#x7528;&#x7A0B;&#x5E8F;&#xFF08;&#x5982;&#x5927;&#x591A;&#x6570;&#x7CFB;&#x7EDF;&#x4E0A;&#x5B89;&#x88C5;&#x7684; Internet Explorer&#xFF09;&#x3002;</p>
<p>New-Object &#x4F7F;&#x7528; .NET Framework &#x8FD0;&#x884C;&#x65F6;&#x53EF;&#x8C03;&#x7528;&#x7684;&#x5305;&#x88C5;&#x5668;&#x521B;&#x5EFA; COM &#x5BF9;&#x8C61;&#xFF0C;&#x56E0;&#x6B64;&#x8C03;&#x7528; COM &#x5BF9;&#x8C61;&#x65F6;&#x5B83;&#x4E0E; .NET Framework &#x5177;&#x6709;&#x76F8;&#x540C;&#x7684;&#x9650;&#x5236;&#x3002; &#x82E5;&#x8981;&#x521B;&#x5EFA; COM &#x5BF9;&#x8C61;&#xFF0C;&#x9700;&#x8981;&#x4E3A; ComObject &#x53C2;&#x6570;&#x6307;&#x5B9A;&#x8981;&#x4F7F;&#x7528;&#x7684; COM &#x7C7B;&#x7684;&#x7F16;&#x7A0B;&#x6807;&#x8BC6;&#x7B26;&#xFF08;&#x6216; ProgId&#xFF09;&#x3002; COM &#x7528;&#x9014;&#x9650;&#x5236;&#x7684;&#x5168;&#x9762;&#x8BA8;&#x8BBA;&#x548C;&#x786E;&#x5B9A;&#x7CFB;&#x7EDF;&#x4E0A;&#x53EF;&#x7528;&#x7684; ProgId &#x5DF2;&#x8D85;&#x51FA;&#x672C;&#x7528;&#x6237;&#x6307;&#x5357;&#x7684;&#x8303;&#x56F4;&#xFF0C;&#x4F46;&#x6765;&#x81EA;&#x73AF;&#x5883;&#x7684;&#x5927;&#x591A;&#x6570;&#x5DF2;&#x77E5;&#x5BF9;&#x8C61;&#xFF08;&#x5982; WSH&#xFF09;&#x90FD;&#x53EF;&#x5728; Windows PowerShell &#x5185;&#x4F7F;&#x7528;&#x3002;</p>
<p>&#x53EF;&#x4EE5;&#x901A;&#x8FC7;&#x6307;&#x5B9A;&#x4EE5;&#x4E0B; progid &#x6765;&#x521B;&#x5EFA; WSH &#x5BF9;&#x8C61;&#xFF1A;WScript.Shell &#x3001;WScript.Network &#x3001;Scripting.Dictionary &#x548C; Scripting.FileSystemObject &#x3002; &#x4EE5;&#x4E0B;&#x547D;&#x4EE4;&#x5C06;&#x521B;&#x5EFA;&#x8FD9;&#x4E9B;&#x5BF9;&#x8C61;&#xFF1A;</p>
<pre><code class="lang-powershell"><span class="hljs-built_in">New-Object</span> -ComObject WScript.Shell
<span class="hljs-built_in">New-Object</span> -ComObject WScript.Network
<span class="hljs-built_in">New-Object</span> -ComObject Scripting.Dictionary
<span class="hljs-built_in">New-Object</span> -ComObject Scripting.FileSystemObject
</code></pre>
<p>&#x5C3D;&#x7BA1;&#x5728; Windows PowerShell &#x4E2D;&#x53EF;&#x901A;&#x8FC7;&#x5176;&#x4ED6;&#x65B9;&#x6CD5;&#x4F7F;&#x7528;&#x8FD9;&#x4E9B;&#x7C7B;&#x7684;&#x5927;&#x591A;&#x6570;&#x529F;&#x80FD;&#xFF0C;&#x4F46;&#x4F7F;&#x7528; WSH &#x7C7B;&#x6267;&#x884C;&#x67D0;&#x4E9B;&#x4EFB;&#x52A1;&#xFF08;&#x5982;&#x521B;&#x5EFA;&#x5FEB;&#x6377;&#x65B9;&#x5F0F;&#xFF09;&#x4ECD;&#x66F4;&#x52A0;&#x7B80;&#x5355;&#x3002;</p>
<h4 id="&#x4F7F;&#x7528;-wscriptshell-&#x521B;&#x5EFA;&#x684C;&#x9762;&#x5FEB;&#x6377;&#x65B9;&#x5F0F;">&#x4F7F;&#x7528; WScript.Shell &#x521B;&#x5EFA;&#x684C;&#x9762;&#x5FEB;&#x6377;&#x65B9;&#x5F0F;</h4>
<p>&#x53EF;&#x4EE5;&#x4F7F;&#x7528; COM &#x5BF9;&#x8C61;&#x5FEB;&#x901F;&#x6267;&#x884C;&#x7684;&#x4E00;&#x4E2A;&#x4EFB;&#x52A1;&#x662F;&#x521B;&#x5EFA;&#x5FEB;&#x6377;&#x65B9;&#x5F0F;&#x3002; &#x5047;&#x8BBE;&#x4F60;&#x60F3;&#x8981;&#x5728;&#x684C;&#x9762;&#x4E0A;&#x521B;&#x5EFA;&#x94FE;&#x63A5;&#x5230; Windows PowerShell &#x4E3B;&#x6587;&#x4EF6;&#x5939;&#x7684;&#x5FEB;&#x6377;&#x65B9;&#x5F0F;&#x3002; &#x9996;&#x5148;&#x9700;&#x8981;&#x521B;&#x5EFA;&#x5BF9; WScript.Shell &#x7684;&#x5F15;&#x7528;&#xFF0C;&#x6211;&#x4EEC;&#x4F1A;&#x5C06;&#x5176;&#x5B58;&#x50A8;&#x5728;&#x540D;&#x4E3A; $WshShell &#x7684;&#x53D8;&#x91CF;&#x4E2D;&#xFF1A;</p>
<pre><code class="lang-powershell"><span class="hljs-variable">$WshShell</span> = <span class="hljs-built_in">New-Object</span> -ComObject WScript.Shell
</code></pre>
<p>Ge-Member &#x53EF;&#x7528;&#x4E8E; COM &#x5BF9;&#x8C61;&#xFF0C;&#x56E0;&#x6B64;&#x4F60;&#x53EF;&#x4EE5;&#x901A;&#x8FC7;&#x952E;&#x5165;&#x4EE5;&#x4E0B;&#x5185;&#x5BB9;&#x6D4F;&#x89C8;&#x5BF9;&#x8C61;&#x7684;&#x6210;&#x5458;&#xFF1A;</p>
<pre><code class="lang-powershell">PS&gt; <span class="hljs-variable">$WshShell</span> | <span class="hljs-built_in">Get-Member</span>

   TypeName: System.__ComObject<span class="hljs-comment">#{41904400-be18-11d3-a28b-00104bd35090}</span>

Name                     MemberType            Definition
----                     ----------            ----------
AppActivate              Method                bool AppActivate (Variant, Va...
CreateShortcut           Method                IDispatch CreateShortcut (str...
...
</code></pre>
<p>Get-Member &#x5177;&#x6709;&#x53EF;&#x9009; InputObject &#x53C2;&#x6570;&#xFF0C;&#x4F60;&#x53EF;&#x4EE5;&#x4F7F;&#x7528;&#x8FD9;&#x4E2A;&#x53C2;&#x6570;&#x800C;&#x4E0D;&#x4F7F;&#x7528;&#x7BA1;&#x9053;&#x4E3A; Get-Member &#x63D0;&#x4F9B;&#x8F93;&#x5165;&#x3002; &#x5982;&#x679C;&#x6539;&#x7528;&#x547D;&#x4EE4; Get-Member-InputObject $WshShell&#xFF0C;&#x4F60;&#x4F1A;&#x5F97;&#x5230;&#x4E0E;&#x5982;&#x4E0A;&#x6240;&#x793A;&#x76F8;&#x540C;&#x7684;&#x8F93;&#x51FA;&#x3002; &#x5982;&#x679C;&#x4F7F;&#x7528; InputObject&#xFF0C;&#x5B83;&#x5C06;&#x89C6;&#x5176;&#x53C2;&#x6570;&#x4E3A;&#x5355;&#x4E2A;&#x9879;&#x3002; &#x8FD9;&#x610F;&#x5473;&#x7740;&#xFF0C;&#x5982;&#x679C;&#x53D8;&#x91CF;&#x4E2D;&#x6709;&#x51E0;&#x4E2A;&#x5BF9;&#x8C61;&#xFF0C;&#x90A3;&#x4E48; Get-Member &#x4F1A;&#x5C06;&#x5B83;&#x4EEC;&#x89C6;&#x4E3A;&#x4E00;&#x4E2A;&#x5BF9;&#x8C61;&#x6570;&#x7EC4;&#x3002; &#x4F8B;&#x5982;&#xFF1A;</p>
<pre><code class="lang-powershell">PS&gt; <span class="hljs-variable">$a</span> = <span class="hljs-number">1</span>,<span class="hljs-number">2</span>,<span class="hljs-string">&quot;three&quot;</span>
PS&gt; <span class="hljs-built_in">Get-Member</span> -InputObject <span class="hljs-variable">$a</span>
TypeName: System.Object[]
Name               MemberType    Definition
----               ----------    ----------
Count              AliasProperty Count = Length
...
</code></pre>
<p>WScript.Shell CreateShortcut &#x65B9;&#x6CD5;&#x63A5;&#x53D7;&#x5355;&#x4E2A;&#x53C2;&#x6570;&#xFF0C;&#x5373;&#x8981;&#x521B;&#x5EFA;&#x7684;&#x5FEB;&#x6377;&#x65B9;&#x5F0F;&#x6587;&#x4EF6;&#x7684;&#x8DEF;&#x5F84;&#x3002; &#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x952E;&#x5165;&#x684C;&#x9762;&#x7684;&#x5B8C;&#x6574;&#x8DEF;&#x5F84;&#xFF0C;&#x4F46;&#x8FD8;&#x6709;&#x66F4;&#x7B80;&#x5355;&#x7684;&#x65B9;&#x6CD5;&#x3002; &#x684C;&#x9762;&#x901A;&#x5E38;&#x7531;&#x5F53;&#x524D;&#x7528;&#x6237;&#x7684;&#x4E3B;&#x6587;&#x4EF6;&#x5939;&#x5185;&#x540D;&#x4E3A; Desktop &#x7684;&#x6587;&#x4EF6;&#x5939;&#x8868;&#x793A;&#x3002; Windows PowerShell &#x5177;&#x6709;&#x53D8;&#x91CF; $Home&#xFF0C;&#x5B83;&#x5305;&#x542B;&#x6B64;&#x6587;&#x4EF6;&#x5939;&#x7684;&#x8DEF;&#x5F84;&#x3002; &#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x901A;&#x8FC7;&#x4F7F;&#x7528;&#x6B64;&#x53D8;&#x91CF;&#x6307;&#x5B9A;&#x4E3B;&#x6587;&#x4EF6;&#x5939;&#x7684;&#x8DEF;&#x5F84;&#xFF0C;&#x7136;&#x540E;&#x901A;&#x8FC7;&#x952E;&#x5165;&#x4EE5;&#x4E0B;&#x5185;&#x5BB9;&#x6DFB;&#x52A0; Desktop &#x6587;&#x4EF6;&#x5939;&#x7684;&#x540D;&#x79F0;&#x548C;&#x8981;&#x521B;&#x5EFA;&#x7684;&#x5FEB;&#x6377;&#x65B9;&#x5F0F;&#x7684;&#x540D;&#x79F0;&#xFF1A;</p>
<pre><code class="lang-powershell"><span class="hljs-variable">$lnk</span> = <span class="hljs-variable">$WshShell</span>.CreateShortcut(<span class="hljs-string">&quot;<span class="hljs-variable">$Home</span>\Desktop\PSHome.lnk&quot;</span>)
</code></pre>
<p>&#x5F53;&#x4F60;&#x5728;&#x53CC;&#x5F15;&#x53F7;&#x5185;&#x4F7F;&#x7528;&#x5916;&#x89C2;&#x7C7B;&#x4F3C;&#x53D8;&#x91CF;&#x540D;&#x79F0;&#x7684;&#x9879;&#x65F6;&#xFF0C;Windows PowerShell &#x5C06;&#x5C1D;&#x8BD5;&#x66FF;&#x6362;&#x5339;&#x914D;&#x7684;&#x503C;&#x3002; &#x5982;&#x679C;&#x4F7F;&#x7528;&#x5355;&#x5F15;&#x53F7;&#xFF0C;Windows PowerShell &#x5C06;&#x4E0D;&#x4F1A;&#x66FF;&#x6362;&#x8BE5;&#x53D8;&#x91CF;&#x503C;&#x3002; &#x4F8B;&#x5982;&#xFF0C;&#x8BF7;&#x5C1D;&#x8BD5;&#x952E;&#x5165;&#x4EE5;&#x4E0B;&#x547D;&#x4EE4;&#xFF1A;</p>
<pre><code class="lang-powershell">PS&gt; <span class="hljs-string">&quot;<span class="hljs-variable">$Home</span>\Desktop\PSHome.lnk&quot;</span>
C:\Documents and Settings\aka\Desktop\PSHome.lnk
PS&gt; <span class="hljs-string">&apos;$Home\Desktop\PSHome.lnk&apos;</span>
<span class="hljs-variable">$Home</span>\Desktop\PSHome.lnk
</code></pre>
<p>&#x6211;&#x4EEC;&#x73B0;&#x5728;&#x6709;&#x4E00;&#x4E2A;&#x540D;&#x4E3A; $lnk &#x7684;&#x53D8;&#x91CF;&#xFF0C;&#x5176;&#x4E2D;&#x5305;&#x542B;&#x65B0;&#x7684;&#x5FEB;&#x6377;&#x65B9;&#x5F0F;&#x5F15;&#x7528;&#x3002; &#x5982;&#x679C;&#x60F3;&#x8981;&#x67E5;&#x770B;&#x5176;&#x6210;&#x5458;&#xFF0C;&#x4F60;&#x53EF;&#x4EE5;&#x901A;&#x8FC7;&#x7BA1;&#x9053;&#x5C06;&#x5B83;&#x4F20;&#x9012;&#x5230; Get-Member&#x3002; &#x4E0B;&#x9762;&#x7684;&#x8F93;&#x51FA;&#x663E;&#x793A;&#x4E86;&#x5B8C;&#x6210;&#x521B;&#x5EFA;&#x5FEB;&#x6377;&#x65B9;&#x5F0F;&#x6240;&#x9700;&#x4F7F;&#x7528;&#x7684;&#x6210;&#x5458;&#xFF1A;</p>
<pre><code class="lang-powershell">PS&gt; <span class="hljs-variable">$lnk</span> | <span class="hljs-built_in">Get-Member</span>
TypeName: System.__ComObject<span class="hljs-comment">#{f935dc23-1cf0-11d0-adb9-00c04fd58a0b}</span>
Name             MemberType   Definition
----             ----------   ----------
...
Save             Method       void Save ()
...
TargetPath       <span class="hljs-built_in">Property</span>     string TargetPath () {get} {set}
</code></pre>
<p>&#x6211;&#x4EEC;&#x9700;&#x8981;&#x6307;&#x5B9A; TargetPath&#xFF08;&#x5B83;&#x662F; Windows PowerShell &#x7684;&#x5E94;&#x7528;&#x7A0B;&#x5E8F;&#x6587;&#x4EF6;&#x5939;&#xFF09;&#xFF0C;&#x7136;&#x540E;&#x901A;&#x8FC7;&#x8C03;&#x7528; Save &#x65B9;&#x6CD5;&#x4FDD;&#x5B58;&#x5FEB;&#x6377;&#x65B9;&#x5F0F; $lnk&#x3002; Windows PowerShell &#x5E94;&#x7528;&#x7A0B;&#x5E8F;&#x6587;&#x4EF6;&#x5939;&#x8DEF;&#x5F84;&#x5B58;&#x50A8;&#x5728;&#x53D8;&#x91CF; $PSHome &#x4E2D;&#xFF0C;&#x56E0;&#x6B64;&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x901A;&#x8FC7;&#x952E;&#x5165;&#x4EE5;&#x4E0B;&#x5185;&#x5BB9;&#x6267;&#x884C;&#x6B64;&#x64CD;&#x4F5C;&#xFF1A;</p>
<pre><code class="lang-powershell"><span class="hljs-variable">$lnk</span>.TargetPath = <span class="hljs-variable">$PSHome</span>
<span class="hljs-variable">$lnk</span>.Save()
</code></pre>
<h2 id="&#x63A7;&#x5236;&#x8BED;&#x53E5;">&#x63A7;&#x5236;&#x8BED;&#x53E5;</h2>
<h3 id="&#x6761;&#x4EF6;&#x5224;&#x65AD;">&#x6761;&#x4EF6;&#x5224;&#x65AD;</h3>
<h4 id="&#x6BD4;&#x8F83;&#x8FD0;&#x7B97;&#x7B26;">&#x6BD4;&#x8F83;&#x8FD0;&#x7B97;&#x7B26;</h4>
<pre><code class="lang-powershell"><span class="hljs-nomarkup">-eq</span> &#xFF1A;&#x7B49;&#x4E8E;
<span class="hljs-nomarkup">-ne</span> &#xFF1A;&#x4E0D;&#x7B49;&#x4E8E;
<span class="hljs-nomarkup">-gt</span> &#xFF1A;&#x5927;&#x4E8E;
<span class="hljs-nomarkup">-ge</span> &#xFF1A;&#x5927;&#x4E8E;&#x7B49;&#x4E8E;
<span class="hljs-nomarkup">-lt</span> &#xFF1A;&#x5C0F;&#x4E8E;
<span class="hljs-nomarkup">-le</span> &#xFF1A;&#x5C0F;&#x4E8E;&#x7B49;&#x4E8E;
<span class="hljs-nomarkup">-contains</span> &#xFF1A;&#x5305;&#x542B;
<span class="hljs-variable">$array</span> <span class="hljs-nomarkup">-contains</span> something

<span class="hljs-nomarkup">-notcontains</span> :&#x4E0D;&#x5305;&#x542B;
!(<span class="hljs-variable">$a</span>): &#x6C42;&#x53CD;
-and &#xFF1A;&#x548C;
-or &#xFF1A;&#x6216;
-xor &#xFF1A;&#x5F02;&#x6216;
<span class="hljs-nomarkup">-not</span> &#xFF1A;&#x9006;
</code></pre>
<h4 id="if-else">if-else</h4>
<pre><code class="lang-powershell">if-else:

<span class="hljs-keyword">if</span>(<span class="hljs-variable">$value</span> <span class="hljs-nomarkup">-eq</span> <span class="hljs-number">1</span>){
    code1
}<span class="hljs-keyword">else</span>{
    code2
}
</code></pre>
<h3 id="&#x5FAA;&#x73AF;&#x8BED;&#x53E5;">&#x5FAA;&#x73AF;&#x8BED;&#x53E5;</h3>
<h4 id="while">while</h4>
<pre><code class="lang-powershell"><span class="hljs-keyword">while</span>(<span class="hljs-variable">$n</span> <span class="hljs-nomarkup">-gt</span> <span class="hljs-number">0</span>){
    code
}
</code></pre>
<h4 id="for">for</h4>
<pre><code class="lang-powershell"><span class="hljs-variable">$sum</span>=<span class="hljs-number">0</span>
<span class="hljs-keyword">for</span>(<span class="hljs-variable">$i</span>=<span class="hljs-number">1</span>;<span class="hljs-variable">$i</span> <span class="hljs-nomarkup">-le</span> <span class="hljs-number">100</span>;<span class="hljs-variable">$i</span>++)
{
    <span class="hljs-variable">$sum</span>+=<span class="hljs-variable">$i</span>
}
<span class="hljs-variable">$sum</span>
</code></pre>
<h4 id="foreach">foreach</h4>
<pre><code class="lang-powershell"><span class="hljs-comment"># &#x6253;&#x5370;&#x51FA;windows&#x76EE;&#x5F55;&#x4E0B;&#x5927;&#x4E8E;1mb&#x7684;&#x6587;&#x4EF6;&#x540D;</span>
<span class="hljs-keyword">foreach</span>(<span class="hljs-variable">$file</span> <span class="hljs-keyword">in</span> dir c:\windows)
{
    <span class="hljs-keyword">if</span>(<span class="hljs-variable">$file</span>.Length <span class="hljs-nomarkup">-gt</span> <span class="hljs-number">1</span>mb)
    {
        <span class="hljs-variable">$File</span>.Name
    }
}
</code></pre>
<h4 id="foreach-object">foreach-object</h4>
<pre><code class="lang-powershell"><span class="hljs-comment"># &#x83B7;&#x53D6;&#x6240;&#x6709;&#x7684;&#x670D;&#x52A1;&#xFF0C;&#x5E76;&#x83B7;&#x53D6;&#x5BF9;&#x5440;&#x8FDB;&#x7A0B;ID&#x662F;&#x5426;&#x5927;&#x4E8E;100</span>
<span class="hljs-built_in">Get-WmiObject</span> Win32_Service | <span class="hljs-built_in">ForEach-Object</span> {<span class="hljs-string">&quot;Name:&quot;</span>+ <span class="hljs-variable">$_</span>.DisplayName, <span class="hljs-string">&quot;, Is ProcessId more than 100:&quot;</span> + (<span class="hljs-variable">$_</span>.ProcessId <span class="hljs-nomarkup">-gt</span> <span class="hljs-number">100</span>)}
</code></pre>
<h2 id="&#x51FD;&#x6570;">&#x51FD;&#x6570;</h2>
<pre><code class="lang-powershell"><span class="hljs-keyword">function</span> Invoke-PortScan {
&lt;<span class="hljs-comment">#</span>
.SYNOPSIS 
&#x7B80;&#x4ECB;

.DESCRIPTION
&#x63CF;&#x8FF0;

.PARAMETER StartAddress
&#x53C2;&#x6570;

.PARAMETER EndAddress
&#x53C2;&#x6570;

.EXAMPLE
PS &gt; Invoke-PortScan -StartAddress <span class="hljs-number">192.168</span>.<span class="hljs-number">0.1</span> -EndAddress <span class="hljs-number">192.168</span>.<span class="hljs-number">0.254</span>
&#x7528;&#x4F8B;
<span class="hljs-comment">#&gt;</span>
code
}
</code></pre>
<h2 id="&#x5F02;&#x5E38;&#x5904;&#x7406;">&#x5F02;&#x5E38;&#x5904;&#x7406;</h2>
<p>Try{
    $connection.open()
    $success = $true
}Catch{
    $success = $false
}</p>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="kerberos/README.md" class="navigation navigation-prev " aria-label="Previous page: 基础篇">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="3. 脚本编写与执行.html" class="navigation navigation-next " aria-label="Next page: 脚本编写与执行">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"基础知识","level":"1.2.1","depth":2,"next":{"title":"脚本编写与执行","level":"1.2.2","depth":2,"path":"3. 脚本编写与执行.md","ref":"3. 脚本编写与执行.md","articles":[]},"previous":{"title":"基础篇","level":"1.2","depth":1,"path":"kerberos/README.md","ref":"kerberos/README.md","articles":[{"title":"基础知识","level":"1.2.1","depth":2,"path":"2. 基础.md","ref":"2. 基础.md","articles":[]},{"title":"脚本编写与执行","level":"1.2.2","depth":2,"path":"3. 脚本编写与执行.md","ref":"3. 脚本编写与执行.md","articles":[]},{"title":"Scoket网络编程","level":"1.2.3","depth":2,"path":"4. Scoket网络编程.md","ref":"4. Scoket网络编程.md","articles":[]},{"title":"端口扫描与服务爆破","level":"1.2.4","depth":2,"path":"5. 端口扫描与服务爆破.md","ref":"5. 端口扫描与服务爆破.md","articles":[]},{"title":"多线程","level":"1.2.5","depth":2,"path":"6. 多线程.md","ref":"6. 多线程.md","articles":[]}]},"dir":"ltr"},"config":{"gitbook":"*","theme":"default","variables":{},"plugins":["livereload"],"pluginsConfig":{"livereload":{},"highlight":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"}},"file":{"path":"2. 基础.md","mtime":"2020-04-13T08:15:13.811Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2020-04-13T09:56:21.455Z"},"basePath":".","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="gitbook/gitbook.js"></script>
    <script src="gitbook/theme.js"></script>
    
        
        <script src="gitbook/gitbook-plugin-livereload/plugin.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

